package com.hs.jhzd.config;

import java.util.ArrayList;
import java.util.concurrent.TimeUnit;

import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.caffeine.CaffeineCache;
import org.springframework.cache.support.SimpleCacheManager;

import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableCaching
public class CacheConfiguration {

  public static final int DEFAULT_MAXSIZE = 50000;
  public static final int DEFAULT_TTL = 1 * 60 * 60;


  /**
   * CacheManager.
   *
   * @return cacheManager
   */
  @Bean
  public CacheManager cacheManager() {
    SimpleCacheManager cacheManager = new SimpleCacheManager();
    ArrayList<CaffeineCache> caches = new ArrayList<>();
    Caffeine<Object, Object> caffeine = Caffeine.newBuilder().recordStats().maximumSize(5000);
    caffeine.expireAfterWrite(24, TimeUnit.HOURS);
    CaffeineCache caffeineCache = new CaffeineCache("fingerprintCache", caffeine.build());
    caches.add(caffeineCache);
    cacheManager.setCaches(caches);

    return cacheManager;
  }

}
